﻿#ifndef UI_SEACH_H
#define UI_SEACH_H

#include <QWidget>
#include <QUdpSocket>
#include <QVector>
#include <QString>
#include <QHostAddress>
#include <QMessageBox>
#include <QList>
#include <QRegExp>
#include <QNetworkAddressEntry>

/* UDP搜索到的设备信息 */
typedef struct udpDeviceInfo_s
{
    QString sn;
    QString ver;
    bool dhcp;
    QString ip;
    QString mac;
    QString gw;
    QString mask;
    QString dns1;
    QString dns2;
    QString model;
}udpDeviceInfo_t;

namespace Ui {
class uiSeach;
}

class uiSeach : public QWidget
{
    Q_OBJECT

public:
    explicit uiSeach(QWidget *parent = 0);
    ~uiSeach();

    void getIpv4(QList<QNetworkAddressEntry> * entries);
    bool isValidIPAddress(const QString &ip);


    QList<QString> m_ipList;
    QList<QNetworkInterface> m_ipAddr;

protected:
    void closeEvent(QCloseEvent *event) override;


signals:
    void startSearch(void);
    void clusterConnect(udpDeviceInfo_t);

private slots:
    void udpReadData(void);
    void sendBroad(void);
    void on_search_clicked();
    void on_connectCluster_clicked();
    void showDevInfo(int row, int column);

private:
    QString xmlSearch(void);
    void xmlRead(QString tree);
    bool udpInfoAdd(udpDeviceInfo_t &dev);


    Ui::uiSeach *ui;
    QUdpSocket *m_udp;
    QList<QNetworkAddressEntry> * m_entries;
    QVector<udpDeviceInfo_t> *m_udpInfo;
    int m_curDevIndex;
};

#endif // UI_SEACH_H
